import json
import sys
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

face_json = sys.argv[1]
license_json = sys.argv[2]

with open(face_json, "r", encoding="utf8") as fp:
    face_json_data = json.load(fp)
with open(license_json, "r", encoding="utf8") as fp:
    license_json_data = json.load(fp)

face_record = []
license_record = []
for ann in face_json_data["annotations"]:
    face_record.append(ann["area"])
for ann in license_json_data["annotations"]:
    #  import pdb;pdb.set_trace()
    license_record.append(ann["bbox"][2] * ann["bbox"][3])

face_record = np.array(face_record)
license_record = np.array(license_record)

#  num_bins = [0,64,256,600,1200,2500,5000]
num_bins = [i * 10 for i in range(60)]


plt.figure(figsize=(9, 5))
# face
ax1 = plt.subplot(121)
n, bins, patches = ax1.hist(face_record, num_bins)
ax1.set_title("face")
plt.ylabel("number_of_area")

# license
ax2 = plt.subplot(122)
n, bins, patches = ax2.hist(license_record, num_bins)
ax2.set_title("license")

plt.xlabel("area")
plt.tight_layout()
plt.show()
plt.savefig("visual_analyzed_result/area_statistic.jpg")
